<!-- Add Modal //-->
<div id="addModal" class="reveal-modal medium tmbModal" data-reveal>
	<p class="p-modal">Tambah pengaturan syahriyah pada tahun ajaran <?php foreach ($list_th as $row) {echo $th = $row->th_ajaran;$idth = $row->id_m_th_ajaran;}?></p>
	<div class="isi-modal">
		<div id="add"></div>	
	</div>
 </div>
<!-- End Add Modal //-->

<!-- Delete Modal //-->
<div id="delModal" class="reveal-modal tiny" data-reveal>
	<p class="p-modal">
	<span id="hpid" class="hpid var-modal" style="display:none;"></span>
	<span id="id_m_th_ajaran" style="display:none;"><?php echo $nis = $this->security->xss_clean($this->uri->segment(3));?></span>
	Yakin ingin menghapus pengaturan syahriyah jenjang <span class="nama var-modal"></span> Rp <span class="2nd var-modal"></span> dari tahun ajaran <span class="3rd var-modal"></span>?</p><br/><br/>
	<span id="loadingDel" style="display:none;">Sedang memproses..</span>
	<span id="errorDel" style="display:none;color:red;">Ma'af, gagal dihapus</span>
	<span class="pull-right">
		<button class="deleteUrl btn btn-xs tmb-utama" id="hapusAturSy"> Yakin</button> 
		<button class="btn tmb-kedua close-reveal-modal close-modal"> Tidak</button>
	</span>
</div>
<!-- End Delete Modal //-->

<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default kotakwidget">
			<div class="panel-heading kepalakotakwidget">
				Pengaturan Besar Tagihan Syahriyah Tahun Ajaran <?php echo $th;?> 
				<span class="pull-right">
					<button data-reveal-id="addModal" data-reveal class="btn btn-sm tmb-tambah tmb-utama" onClick="add_atur_sy('<?php echo $idth;?>')"><i class="fa fa-plus"></i> Tambah</button>
				</span>				
			</div>
				
				<div class="panel-body">
					<div class="row">
						<div class="col-md-12">
							<div id="contentAturSy">
							<table class="table table-condensed" id="th_ajaran">
							  <thead>
								<tr>
									<th width="30">#</th>
									<th width="160">Jenjang</th>
									<th>Besar Syahriyah</th>
								</tr>
							  </thead>
							  <tbody>
								<?php 
									if(count($list)>0){
										$i = 1; 
										foreach ($list as $row) {
								?>
								<tr class="hover">
									<td><?php echo $i++ ?></td>
									<td><?php echo $row->j_pendidikan; ?></td> 
									<td>
										<?php echo $row->besar_sy; ?>
										<a class="editorLink pull-right" data-reveal-id="delModal" nama="<?php echo $row->j_pendidikan; ?>" 2nd="<?php echo $row->besar_sy; ?>" 3rd="<?php echo $th;?>" hpid="<?php echo $row->id_a_sy;?>" data-reveal><span class="glyphicon glyphicon-floppy-remove"></span></a>
									</td> 
								</tr>
								<?php
										}
									}else{
								?>
								<tr>
									<td colspan="3"><center>Belum ada pengaturan besar tagihan syahriyah pada tahun ajaran <?php echo $th;?> </center></td>
								</tr>
								<?php
									}
								?>
							  </tbody>
							</table>
							</div>
						</div>
					</div>
				</div>
		</div>
	</div>	
</div>
<script>
// Auto Focus Input Form
$(document).on('opened', '[data-reveal]', function () {
	$('.clearable').focus();
});
// Add
function add_atur_sy(id_m_th_ajaran){
	$.ajax({
		type: "POST",
		url : "<?php echo site_url(); ?>a_sy/add",
		data: "id_m_th_ajaran="+id_m_th_ajaran,
		cache: false,
		success: function(response) {
			$('#add').html(response);
		}
	});
	return false;
}
// Save
$(document).ajaxComplete(function(){
	$('#SaveAturSy').bind('submit', function(event) {
		var link = $(this).attr('action');
		var id_m_th_ajaran = $("#id_m_th_ajaran").text();
		$.ajax({
			url: link,
			type: "POST",
			data: $(this).serialize(),
			cache: false,
			beforeSend: function(){
				$('#errorAdd').hide();
				$('#loadingAdd').show();
			},          
			success: function() {
				var $container = $("#contentAturSy");
				$container.load("<?php echo site_url(); ?>a_sy/refresh/"+id_m_th_ajaran);
				
				$('#loadingAdd').hide();
				$('#addModal').foundation('reveal', 'close');
			},
			error:function(){
				$('#loadingAdd').hide();
				$('#errorAdd').show();
			}
		});
		return false; // dont post it automatically
	});
});
// Delete
$("#hapusAturSy").on("click", function(){
	var id_a_sy= $("#hpid").text();
	var id_m_th_ajaran = $("#id_m_th_ajaran").text();
		$.ajax({
			type: "POST",
			data: "id_a_sy="+id_a_sy,
			url : "<?php echo site_url(); ?>a_sy/delete",				
			cache: false,
			beforeSend: function(){
				$('#loadingDel').show();
				$('#errorDel').hide();
			},  
			success: function(){
				var $container = $("#contentAturSy");
				$container.load("<?php echo site_url(); ?>a_sy/refresh/"+id_m_th_ajaran);

				$('#loadingDel').hide();
				$('#delModal').foundation('reveal', 'close');					
			}, 
			error:function(){
				$('#loadingDel').hide();
				$('#errorDel').show();
			}
		});
		return false; 
	});
</script>